package com.aletto.general_store.presenters;

import com.aletto.general_store.data.DataRepository;
import com.aletto.general_store.data.model.Goods;
import com.aletto.general_store.data.model.PageResponse;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.sisyphus.spinach.core.INetPageTask;
import com.sisyphus.spinach.core.model.IPageResponse;
import com.sisyphus.spinach.core.model.IResponse;
import com.sisyphus.spinach.network.presenters.NetPageTask;

import androidx.recyclerview.widget.RecyclerView;
import io.reactivex.rxjava3.core.Observable;

/**
 * 搜索商品列表
 */
public class SearchGoodsPageTemplate extends GoodsPageTemplate {

    private String keyword;

    public SearchGoodsPageTemplate(RecyclerView recyclerView, SmartRefreshLayout refreshLayout) {
        super(recyclerView, refreshLayout);
    }

    public SearchGoodsPageTemplate params(String keyword){
        this.keyword = keyword;
        return this;
    }

    @Override
    public BaseQuickAdapter<Goods, BaseViewHolder> adapter(RecyclerView recyclerView) {
        return super.adapter(recyclerView);
    }

    @Override
    public INetPageTask.Presenter<Goods, INetPageTask.View<Goods>> presenter() {
        return new NetPageTask<>() {
            @Override
            public Observable<? extends IResponse<? extends IPageResponse<Goods>>> execute(int page) {
                return DataRepository.getInstance().searchGoods(page, PageResponse.SIZE, keyword);
            }
        };
    }

}
